package com.example.photography.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.example.photography.R;
import com.example.photography.adapter.InterestGridViewAdapter;
import com.example.photography.bean.Interest_Bean;
import com.example.photography.common.BaseActivity;
import com.example.photography.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Interest_choose extends BaseActivity {


    @BindView(R.id.tv_pass)
    TextView tvPass;
    @BindView(R.id.gv_item)
    GridView gvItem;
    @BindView(R.id.tv_refresh)
    TextView tvRefresh;
    @BindView(R.id.iv_confirm)
    ImageView ivConfirm;

    @Override
    protected void initData() {
        //装载GridView
        initGridView();
        //点击事件
        initListen();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.choose_interest;
    }


    private void initGridView() {
        String json = Util.getJson(this, "interest.json");
        Interest_Bean interestBean = JSON.parseObject(json, Interest_Bean.class);
        Interest_Bean.DataBean dataBean = interestBean.getData();
        if (dataBean != null) {//有数据
            //设置适配器
            InterestGridViewAdapter interestGridViewAdapter = new InterestGridViewAdapter(dataBean.getInterest(), this);
            gvItem.setAdapter(interestGridViewAdapter);
        } else {//没数据
            Util.showToast(this, "未获取到兴趣信息~");
        }

    }

    private void initListen() {
        //跳过
        tvPass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Util.showToast(Interest_choose.this, "点击了跳过按钮~");
            }
        });
        //刷新
        tvRefresh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Util.showToast(Interest_choose.this, "点击了刷新按钮~");
            }
        });
        //确认
        ivConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Util.showToast(Interest_choose.this, "点击了确认按钮~");
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
